/*
 *  Copyright 2008 The Apache Software Foundation
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package org.fcs.framework.generator;

import java.sql.Types;
import java.util.HashMap;
import java.util.Map;

/**
 * TODO - Delete Me
 * 
 * @author Jeff Butler
 */
public class JavaTypeNameTranslator {

    private static Map<Integer, String> typeToName;

    static {
        typeToName = new HashMap<Integer, String>();
//        typeToName.put(Types.ARRAY, "ARRAY"); //$NON-NLS-1$
        typeToName.put(Types.BIGINT, "Long"); //$NON-NLS-1$
        typeToName.put(Types.BINARY, "byte[]"); //$NON-NLS-1$
        typeToName.put(Types.BIT, "Boolean"); //$NON-NLS-1$
//        typeToName.put(Types.BLOB, "BLOB"); //$NON-NLS-1$
//        typeToName.put(Types.BOOLEAN, "BOOLEAN"); //$NON-NLS-1$
        typeToName.put(Types.CHAR, "String"); //$NON-NLS-1$
        typeToName.put(Types.CLOB, "String"); //$NON-NLS-1$
//        typeToName.put(Types.DATALINK, "DATALINK"); //$NON-NLS-1$
        typeToName.put(Types.DATE, "Date"); //$NON-NLS-1$
        typeToName.put(Types.DECIMAL, "java.math.BigDecimal"); //$NON-NLS-1$
//        typeToName.put(Types.DISTINCT, "DISTINCT"); //$NON-NLS-1$
        typeToName.put(Types.DOUBLE, "Double"); //$NON-NLS-1$
        typeToName.put(Types.FLOAT, "Float"); //$NON-NLS-1$
        typeToName.put(Types.INTEGER, "Integer"); //$NON-NLS-1$
//        typeToName.put(Types.JAVA_OBJECT, "JAVA_OBJECT"); //$NON-NLS-1$
//        typeToName.put(Types.LONGVARBINARY, "LONGVARBINARY"); //$NON-NLS-1$
        typeToName.put(Types.LONGVARCHAR, "String"); //$NON-NLS-1$
        typeToName.put(Types.NCHAR, "String"); //$NON-NLS-1$
        typeToName.put(Types.NCLOB, "String"); //$NON-NLS-1$
        typeToName.put(Types.NVARCHAR, "String"); //$NON-NLS-1$
        typeToName.put(Types.LONGNVARCHAR, "String"); //$NON-NLS-1$
//        typeToName.put(Types.NULL, "NULL"); //$NON-NLS-1$
        typeToName.put(Types.NUMERIC, "java.math.BigDecima"); //$NON-NLS-1$
//        typeToName.put(Types.OTHER, "OTHER"); //$NON-NLS-1$
        typeToName.put(Types.REAL, "Float"); //$NON-NLS-1$
//        typeToName.put(Types.REF, "REF"); //$NON-NLS-1$
        typeToName.put(Types.SMALLINT, "Short"); //$NON-NLS-1$
//        typeToName.put(Types.STRUCT, "STRUCT"); //$NON-NLS-1$
        typeToName.put(Types.TIME, "java.util.Date"); //$NON-NLS-1$
        typeToName.put(Types.TIMESTAMP, "java.util.Date"); //$NON-NLS-1$
        typeToName.put(Types.TINYINT, "Short"); //$NON-NLS-1$
        typeToName.put(Types.VARBINARY, "byte[]"); //$NON-NLS-1$
        typeToName.put(Types.VARCHAR, "String"); //$NON-NLS-1$
    }

    /**
     * Utility Class - no instances
     */
    private JavaTypeNameTranslator() {
        super();
    }

    /**
     * Translates from a java.sql.Types values to the proper iBATIS string
     * representation of the type.
     * 
     * @param jdbcType
     *            a value from java.sql.Types
     * @return the iBATIS String representation of a JDBC type
     */
    public static String getJavaTypeName(int jdbcType) {
        String answer = typeToName.get(jdbcType);
        if (answer == null) {
            answer = "OTHER"; //$NON-NLS-1$
        }

        return answer;
    }

}
